package com.imooc.web;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.imooc.bo.ShopcatBo;
import com.imooc.utils.CookieUtils;
import com.imooc.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

/**
 * <h1>购物车接口</h1>
 *
 * @author : dzj
 * @create: 2022-02-19 20:48
 */
@Api(value = "购物车接口控制器", tags = {"购物车接口相关api"})
@Slf4j
@RestController
@RequestMapping("/shopcart")
public class ShopcatController {
    public static final String shop_cart_name = "";
    @PostMapping("/add")
    @ApiOperation(value = "添加商品到购物车",notes = "添加商品到购物车",httpMethod = "POST")
    public Result add(
            @ApiParam(name = "keyWords",value = "搜索关键词",required = true) @RequestParam(required = true)   String userId,
            @RequestBody @Valid   ShopcatBo shopcatBo,
            HttpServletResponse response,
            HttpServletRequest request
            ) {
        if(StringUtils.isBlank(userId)) {
            return Result.errorMsg("用户编号不得为空");
        }
        log.info("bo: {}",shopcatBo);
        // todo  前端用户再登录的情况下,添加商品到购物车, 会同时再后端同步购物车到rendis缓存
      //  String cookieValue = CookieUtils.getCookieValue(request, shop_cat_name);

        return Result.ok();

    }

    @PostMapping("/del")
    @ApiOperation(value = "删除商品到购物车",notes = "删除商品到购物车",httpMethod = "POST")
    public Result del(
            @ApiParam(name = "userId",value = "用户编号",required = true) @RequestParam(required = true)   String userId,
            @ApiParam(name = "keyWords",value = "规格编号",required = true) @RequestParam(required = true)   String specId,
            HttpServletResponse response,
            HttpServletRequest request
    ) {
        if(StringUtils.isBlank(userId)||StringUtils.isBlank(specId)) {
            return Result.errorMsg("传入信息不完整");
        }
        // todo  前端用户再登录的情况下,同步删除后端购物车商品 ,
        return Result.ok();

    }
}
